package com.example.rmqdemo.service;


import com.example.rmqdemo.domain.User;
import org.apache.logging.log4j.message.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @Author:徐莹
 * @Date:2025/02/28 15:53:22
 */

@Service
public class ReserveService {
//    @RabbitListener(queues = "fanout_queue_email")
//    public void reserve(String msg) {
//
//        System.out.println("reserve: " + msg);
//    }
//发布订阅模式
    @RabbitListener(bindings =@QueueBinding(value =
    @Queue("fanout_queue_email2"), exchange =
    @Exchange(value = "fanout_exchange",type = "fanout")))
    public void psubConsumerEmailAno(String msg) {
        System.out.println("邮件业务接收到消息： "+msg);
    }
    @RabbitListener(bindings =@QueueBinding(value =
    @Queue("fanout_queue_sms2"),exchange =
    @Exchange(value = "fanout_exchange",type = "fanout")))
    public void psubConsumerSmsAno(String msg) {
        System.out.println("短信业务接收到消息： "+msg);
    }
//路由模式
    @RabbitListener(bindings =@QueueBinding(value =
    @Queue("routing_queue_error"),exchange =
    @Exchange(value = "routing_exchange",type = "direct"),
            key = "error_routing_key"))
    public void routingConsumerError(String message) {
        System.out.println("接收到error级别日志消息： "+message);
    }
    @RabbitListener(bindings =@QueueBinding(value =
    @Queue("routing_queue_all"),exchange =
    @Exchange(value = "routing_exchange",type = "direct"),
            key ={ "error_routing_key","info_routing_key","warning_routing_key"}))
    public void routingConsumerALL(String message) {
        System.out.println("接收到info error warming级别日志消息： "+message);
    }
    //topics模式
    @RabbitListener(bindings =@QueueBinding(value =
    @Queue("topic_queue_email"),exchange =
    @Exchange(value = "topic_exchange",type = "topic"),
            key = "info.#.email.#"))
    public void topicConsumerEmail(String message) {
        System.out.println("接收到邮件订阅需求处理消息： "+message);
    }

    @RabbitListener(bindings =@QueueBinding(value =
    @Queue("topic_queue_sms"),exchange =
    @Exchange(value = "topic_exchange",type = "topic"),
            key = "info.#.sms.#"))
    public void topicConsumerSms(String message) {
        System.out.println("接收到短信订阅需求处理消息： "+message);
    }

}
